<template>
  <div class="app-container">
    <el-form class="top" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="发生经度" prop="specialLng">
        <el-input
          v-model="queryParams.specialLng"
          placeholder="请输入发生经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发生纬度" prop="specialLat">
        <el-input
          v-model="queryParams.specialLat"
          placeholder="请输入发生纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理人" prop="specialPerson">
        <el-input
          v-model="queryParams.specialPerson"
          placeholder="请输入处理人名字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理状态" prop="specialState">
        <el-select v-model="queryParams.specialState" placeholder="请选择处理状态" clearable>
          <el-option
            v-for="dict in dict.type.task_special_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="发生时间" prop="specialHappenTime">
        <el-date-picker clearable
                        v-model="queryParams.specialHappenTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择发生时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="处理时间" prop="specialDoTime">
        <el-date-picker clearable
                        v-model="queryParams.specialDoTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择处理时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="specialOverTime">
        <el-date-picker clearable
                        v-model="queryParams.specialOverTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="花费时间" prop="specialCost">
        <el-input
          v-model="queryParams.specialCost"
          placeholder="请输入花费时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理结果" prop="specialResult">
        <el-select v-model="queryParams.specialResult" placeholder="请选择处理结果" clearable>
          <el-option
            v-for="dict in dict.type.sys_common_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['task:special:add']"
        >新增</el-button>
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['task:special:edit']"
        >修改</el-button>
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['task:special:remove']"
        >删除</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['task:special:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>

<!--    <el-table v-loading="loading" :data="specialList" @selection-change="handleSelectionChange">-->
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="id" align="center" prop="specialId" />-->
<!--      <el-table-column label="发生经度" align="center" prop="specialLng" />-->
<!--      <el-table-column label="发生纬度" align="center" prop="specialLat" />-->
<!--      <el-table-column label="处理人名字" align="center" prop="specialPerson" />-->
<!--      <el-table-column label="处理状态" align="center" prop="specialState">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.task_special_state" :value="scope.row.specialState"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="发生时间" align="center" prop="specialHappenTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.specialHappenTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="处理时间" align="center" prop="specialDoTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.specialDoTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="结束时间" align="center" prop="specialOverTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.specialOverTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="花费时间" align="center" prop="specialCost" />-->
<!--      <el-table-column label="处理结果" align="center" prop="specialResult">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.specialResult"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['task:special:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['task:special:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--    </el-table>-->
    <el-col :span="6" class="card-box" v-for="item in this.specialList">
      <el-card class="card-front":style="{backgroundImage:'url(https://www.universalbeijingresort.com/sites/default/files/2021-09/Jurasssic%20Flyer_1.jpg)'}">
        <div class="card-header">
          <div class="card-thing">
            <span>事件{{item.specialId}}</span>
            <div class="card-title">处理人：{{item.specialPerson}}</div>
            <img class="card-symbol" src="./place.png">
            <span class="card-title">{{item.specialLat}}N</span>
            <span class="card-title">{{item.specialLng}}E</span>
            <div>
              <span class="card-title">事件状态：</span>
              <span class="card-state">{{dict.type.task_special_state[item.specialState].label}}</span>
            </div>
            <div class="card-title">报警时间：{{item.specialHappenTime}}</div>
            <div class="card-title">解决时间：{{item.specialDoTime}}</div>
            <div class="card-title">结束时间：{{item.specialOverTime}}</div>
              <span class="card-title">花费时间：</span>
              <span class="card-title">{{item.specialCost}}</span>
              <span class="card-title">min</span>
            <div>
              <span class="card-title">处理结果:</span>
              <span class="card-state">{{dict.type.sys_common_status[item.specialResult].label}}</span>
            </div>
          </div>
        </div>
        <div class="card-bottom">
          <el-button
            class="card-button-edit"
            size="mini"
            @click="handleUpdate(item)"
            v-hasPermi="['task:special:edit']"
          >修改</el-button>
          <el-button
            class="card-button-delete"
            size="mini"
            @click="handleDelete(item)"
            v-hasPermi="['task:special:remove']"
          >删除</el-button>
        </div>
      </el-card>
    </el-col>
    <!--    为了让分页的那个条下去，不要错位-->
    <div style="clear: both;"></div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改特殊情况发生管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="发生经度" prop="specialLng">
          <el-input v-model="form.specialLng" placeholder="请输入发生经度" />
        </el-form-item>
        <el-form-item label="发生纬度" prop="specialLat">
          <el-input v-model="form.specialLat" placeholder="请输入发生纬度" />
        </el-form-item>
        <el-form-item label="处理人" prop="specialPerson">
          <el-input v-model="form.specialPerson" placeholder="请输入处理人名字" />
        </el-form-item>
        <el-form-item label="处理状态" prop="specialState">
          <el-select v-model="form.specialState" placeholder="请选择处理状态">
            <el-option
              v-for="dict in dict.type.task_special_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发生时间" prop="specialHappenTime">
          <el-date-picker clearable
                          v-model="form.specialHappenTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择发生时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理时间" prop="specialDoTime">
          <el-date-picker clearable
                          v-model="form.specialDoTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择处理时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="specialOverTime">
          <el-date-picker clearable
                          v-model="form.specialOverTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="花费时间" prop="specialCost">
          <el-input v-model="form.specialCost" placeholder="请输入花费时间" />
        </el-form-item>
        <el-form-item label="处理结果" prop="specialResult">
          <el-select v-model="form.specialResult" placeholder="请选择处理结果">
            <el-option
              v-for="dict in dict.type.sys_common_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSpecial, getSpecial, delSpecial, addSpecial, updateSpecial } from "@/api/task/special";

export default {
  name: "Special",
  dicts: ['task_special_state', 'sys_common_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 特殊情况发生管理表格数据
      specialList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 12,
        specialLng: null,
        specialLat: null,
        specialPerson: null,
        specialState: null,
        specialHappenTime: null,
        specialDoTime: null,
        specialOverTime: null,
        specialCost: null,
        specialResult: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询特殊情况发生管理列表 */
    getList() {
      this.loading = true;
      listSpecial(this.queryParams).then(response => {
        this.specialList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        specialId: null,
        specialLng: null,
        specialLat: null,
        specialPerson: null,
        specialState: null,
        specialHappenTime: null,
        specialDoTime: null,
        specialOverTime: null,
        specialCost: null,
        specialResult: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.specialId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加特殊情况发生管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const specialId = row.specialId || this.ids
      getSpecial(specialId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改特殊情况发生管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.specialId != null) {
            updateSpecial(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSpecial(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const specialIds = row.specialId || this.ids;
      this.$modal.confirm('是否确认删除特殊情况发生管理编号为"' + specialIds + '"的数据项？').then(function() {
        return delSpecial(specialIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('task/special/export', {
        ...this.queryParams
      }, `special_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
